{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}
var
	a:array[1..100] of integer;
	i,n,p:integer;
	flag:boolean;
begin
	readln(n);
	for i:=1 to n do
		a[i]:=i;
	flag:=true;
	while(n>2)do
	begin
		p:=1;
		if(flag)then
		begin
			for i:= 1 to n do
			if((i mod 3)<>0)then
			begin
				a[p]:=a[i];
				inc(p);
			end;
		end
		else
		begin
			for i:=1 to n do
			if(((n-3+1)mod 3) <> (i mod 3))then
			begin
				a[p]:=a[i];
				inc(p);
			end;
		end;
		n:=p-1;
		flag:=not flag;
	end;
	if(flag)then
		writeln(a[1])
	else
		writeln(a[2]);
end.
